package course.group;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import people.Person;
import people.student.Student;
import permission.RoleManager;
import permission.Roleable;
import permission.Secureable;
import permission.role.Role;

/**
 * 
 */

/**
 * This is a simple class that encapsulates
 * information for a group.
 * 
 * @author Andreas Waldherr (e1028787@student.tuwien.ac.at)
 *
 */
public class Group implements Secureable {

	private String description;
	private int groupnumber;
	private Person tutor;
	private List<Student> students = new ArrayList<Student>();
	
	private final List<Role> ACCESS_ROLES = new ArrayList<Role>();
	
	public Group(int groupnumber, String description, Person tutor){
		setGroupnumber(groupnumber);
		setDescription(description);
		setTutor(tutor);
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public int getGroupnumber() {
		return groupnumber;
	}

	public void setGroupnumber(int groupnumber) {
		this.groupnumber = groupnumber;
	}

	public List<Student> getStudents(Roleable person) {
		boolean accessGranted = RoleManager.INSTANCE.isAccessGranted(this, person);
		if(accessGranted) {
			return students;
		} else {
			return new ArrayList<Student>();
		}
	}

	public void setStudents(List<Student> students) {
		this.students = students;
	}

	public Person getTutor() {
		return tutor;
	}

	public void setTutor(Person tutor) {
		this.tutor = tutor;
	}

	@Override
	public Collection<Role> getAccessRoles() {
		return ACCESS_ROLES;
	}

	@Override
	public void addAccessRole(Role role) {
		ACCESS_ROLES.add(role);
	}
	
}
